<?php

namespace App\Http\Controllers;

use App\http\Model\Parking;
use App\Http\Model\Parkingspace;
use Illuminate\Http\Request;

class ParkingspaceController extends Controller
{
    public function getparkingspace(){//获取停车位方法
        $data = Parkingspace::all()->toArray();//查表parkingspace
        foreach ($data as $k => $v) {
            $parking_res = Parking::where('id','=',$v['parking_id'])->get();//遍历插入停车信息parking
            if($parking_res){
                $parking = $parking_res->toArray();
            }else{
                $parking = [];
            }
            $data[$k]['parking'] = $parking;

        }

        return view('home/rent/parkingspace',compact('data'));
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()//车位地图页显示
    {
        $data = Parkingspace::all()->toArray();//查车位表parkingspace
        foreach ($data as $k => $v) {
            $parking_res = Parking::where('id','=',$v['parking_id'])->get();//遍历查找
            if($parking_res){
                $parking = $parking_res->toArray();
                if($parking){
                    $time_diff = timeDiff($parking[0]['drivein_time'],time());
                    $time_diff = $time_diff['day'].'天'.$time_diff['hour'].'小时'.$time_diff['min'].'分';
                    $parking[0]['time_diff'] = $time_diff;
                }
            }else{
                $parking = [];
            }
            $data[$k]['parking'] = $parking;

        }
//        p($data);
        return view('home/parkingspace/index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
